var e = require;
var t = module;
var o = function o() {
    window.localStorage || (window.localStorage = cc.sys.localStorage),
        window.sessionStorage || (window.sessionStorage = cc.sys.localStorage);
    var e = "",
        t = "";
    "undefined" != typeof lplatform &&
        ((e = lplatform.params.llabName + ":" + lplatform.channel), (t = lplatform.params.tdappid));
    var o = "https://h5.udrig.com/app/v1",
        n =
        "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ?

        function(e) {
            return typeof e === "undefined" ? "undefined" : typeof e;
        } :
        function(e) {
            return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ?
                "symbol" :
                typeof e === "undefined" ?
                "undefined" :
                typeof e;
        },
        i = (function(e) {
            var t,
                o,
                i = 0,
                a = e.document,
                r = /^(?:text|application)\/javascript/i,
                s = /^(?:text|application)\/xml/i,
                d = "application/json",
                c = "text/html",
                l = /^\s*$/,
                h = function n(i) {
                    var a = S({}, i || {});
                    for (t in n.settings) {
                        void 0 === a[t] && (a[t] = n.settings[t]);
                    }
                    (y = a).global && 0 == h.active++ && u(y),
                        a.crossDomain ||
                        (a.crossDomain = /^([\w-]+:)?\/\/([^\/]+)/.test(a.url) && RegExp.$2 != e.location.host);
                    var m = a.dataType;
                    if (((i = /=\?/.test(a.url)), "jsonp" == m || i))
                        return i || (a.url = w(a.url, "callback=?")), n.JSONP(a);
                    a.url || (a.url = e.location.toString()), v(a);
                    var b,
                        y = a.accepts[m],
                        A = ((i = {}), /^([\w-]+:)\/\//.test(a.url) ? RegExp.$1 : e.location.protocol),
                        R = n.settings.xhr();
                    for (o in (a.crossDomain || (i["X-Requested-With"] = "XMLHttpRequest"),
                            y &&
                            (-1 < (i.Accept = y).indexOf(",") && (y = y.split(",", 2)[0]),
                                R.overrideMimeType && R.overrideMimeType(y)),
                            (a.contentType || (a.data && "GET" != a.type.toUpperCase())) &&
                            (i["Content-Type"] = a.contentType || "application/x-www-form-urlencoded"),
                            (a.headers = S(i, a.headers || {})),
                            (R.onreadystatechange = function() {
                                if (4 == R.readyState) {
                                    clearTimeout(b);
                                    var e,
                                        t = !1;
                                    if (
                                        (200 <= R.status && R.status < 300) ||
                                        304 == R.status ||
                                        (0 == R.status && "file:" == A)
                                    ) {
                                        (m =
                                            m ||
                                            ((o = R.getResponseHeader("content-type")) &&
                                                (o == c ?
                                                    "html" :
                                                    o == d ?
                                                    "json" :
                                                    r.test(o) ?
                                                    "script" :
                                                    s.test(o) && "xml")) ||
                                            "text"),
                                        (e = R.responseText);
                                        try {
                                            "script" == m
                                                ?
                                                (0, eval)(e) :
                                                "xml" == m ?
                                                (e = R.responseXML) :
                                                "json" == m && (e = l.test(e) ? null : JSON.parse(e));
                                        } catch (e) {
                                            t = e;
                                        }
                                        t ? f(t, "parsererror", R, a) : p(e, R, a);
                                    } else f(null, "error", R, a);
                                }
                                var o;
                            }),
                            (i = !("async" in a) || a.async),
                            R.open(a.type, a.url, i),
                            a.headers)) {
                        R.setRequestHeader(o, a.headers[o]);
                    }
                    return !1 ===
                        (function(e, t) {
                            var o = t.context;
                            if (!1 === t.beforeSend.call(o, e, t) || !1 === u(t)) return !1;
                            u(t);
                        })(R, a) ?
                        (R.abort(), !1) :
                        (0 < a.timeout &&
                            (b = setTimeout(function() {
                                (R.onreadystatechange = g), R.abort(), f(null, "timeout", R, a);
                            }, a.timeout)),
                            R.send(a.data || null),
                            R);
                };

            function u(e) {
                if (e.global) return !0;
            }

            function p(e, t, o) {
                var n = o.context,
                    i = "success";
                o.success.call(n, e, i, t), u(o), m(i, t, o);
            }

            function f(e, t, o, n) {
                var i = n.context;
                n.error.call(i, o, t, e), u(n), m(t, o, n);
            }

            function m(e, t, o) {
                var n = o.context;
                o.complete.call(n, t, e), u(o), (o = o).global && !--h.active && u(o);
            }

            function g() {}

            function w(e, t) {
                return (e + "&" + t).replace(/[&?]{1,2}/, "?");
            }

            function v(e) {
                var t, o;
                "object" === n(e.data) &&
                    (e.data =
                        ((t = e.data),
                            ((o = []).add = function(e, t) {
                                this.push(b(e) + "=" + b(t));
                            }),
                            (function e(t, o, i, a) {
                                var r = "array" == typeof o;
                                for (var s in o) {
                                    var d = o[s];
                                    a && (s = i ? a : a + "[" + (r ? "" : s) + "]"), !a && r ?
                                        t.add(d.name, d.value) :
                                        (i ? "array" == typeof d : "object" === (void 0 === d ? "undefined" : n(d))) ?
                                        e(t, d, i, s) :
                                        t.add(s, d);
                                }
                            })(o, t, void 0),
                            o.join("&").replace("%20", "+"))), !e.data || (e.type && "GET" != e.type.toUpperCase()) || (e.url = w(e.url, e.data));
            }
            (h.active = 0),
            (h.JSONP = function(t) {
                if (!("type" in t)) return h(t);
                var o,
                    n = "jsonp" + ++i,
                    r = a.createElement("script"),
                    s = {
                        abort: function abort() {
                            n in e && (e[n] = g), m("abort", s, t);
                        }
                    },
                    d = a.getElementsByTagName("head")[0] || a.documentElement;
                return (
                    t.error &&
                    (r.onerror = function() {
                        s.abort(), t.error();
                    }),
                    (e[n] = function(i) {
                        clearTimeout(o), delete e[n], p(i, s, t);
                    }),
                    v(t),
                    (r.src = t.url.replace(/=\?/, "=" + n)),
                    d.insertBefore(r, d.firstChild),
                    0 < t.timeout &&
                    (o = setTimeout(function() {
                        s.abort(), m("timeout", s, t);
                    }, t.timeout)),
                    s
                );
            }),
            (h.settings = {
                type: "GET",
                beforeSend: g,
                success: g,
                error: g,
                complete: g,
                context: null,
                global: !0,
                xhr: function xhr() {
                    return new e.XMLHttpRequest();
                },
                accepts: {
                    script: "text/javascript, application/javascript",
                    json: d,
                    xml: "application/xml, text/xml",
                    html: c,
                    text: "text/plain"
                },
                crossDomain: !1,
                timeout: 0
            }),
            (h.get = function(e, t) {
                return h({ url: e, success: t });
            }),
            (h.post = function(e, t, o, n) {
                return (
                    "function" == typeof t && ((n = n || o), (o = t), (t = null)),
                    h({ type: "POST", url: e, data: t, success: o, dataType: n })
                );
            }),
            (h.getJSON = function(e, t) {
                return h({ url: e, success: t, dataType: "json" });
            });
            var b = encodeURIComponent;

            function S(e) {
                return (
                    Array.prototype.slice.call(arguments, 1).forEach(function(o) {
                        for (t in o) {
                            void 0 !== o[t] && (e[t] = o[t]);
                        }
                    }),
                    e
                );
            }
            return { ajax: h };
        })(window),
        a = {
            deviceId: "",
            appkey: t || "",
            appProfile: { versionName: "", versionCode: "", initTime: "", sdkVersion: "H5+APP+v1.0.6", partner: "" },
            deviceProfile: {
                pixel: "",
                language: navigator.language,
                timezone: (new Date().getTimezoneOffset() / 60) * -1
            },
            msgs: []
        },
        r = { type: 2, data: { id: "", start: 0, duration: 0 } },
        s = { autoTrack: !0 };
    !(function() {
        for (var e = document.getElementsByTagName("script"), t = 0; t < e.length; t++) {
            var o = e[t].getAttribute("td-autoTrack");
            if ("false" === o || !1 === o) {
                s.autoTrack = !1;
                break;
            }
        }
    })();
    var d = new Date().getTime();

    function c(e, t, o) {
        if (void 0 === t) {
            var n = null;
            if (document.cookie && "" != document.cookie)
                for (var i = document.cookie.split(";"), a = 0; a < i.length; a++) {
                    var r = i[a];
                    if (r.substring(0, e.length + 1) == e + "=") {
                        n = decodeURIComponent(r.substring(e.length + 1));
                        break;
                    }
                }
            return n;
        }
        (o = o || {}), null === t && ((t = ""), (o.expires = -1));
        var s = "";
        o.expires &&
            ("number" == typeof o.expires || o.expires.toUTCString) &&
            ("number" == typeof o.expires ? (c = new Date()).setTime(c.getTime() + 864e5 * o.expires) : (c = o.expires),
                (s = "; expires=" + c.toUTCString()));
        var d = o.path ? "; path=" + o.path : "",
            c = o.domain ? "; domain=" + o.domain : "";
        (o = o.secure ? "; secure" : ""), (document.cookie = [e, "=", encodeURIComponent(t), s, d, c, o].join(""));
    }
    (s.localStorage = {
        add: function add(e, t) {
            this.addLocalStorage(e, t), "sessionId" != e && this.addCookie(e, t);
        },
        get: function get(e) {
            return this.getLocalStorage(e) || this._getCookie(e);
        },
        create: function create() {
            c("__TD_LOCAL") || (this._addCookie(""), window.localStorage);
        },
        addCookie: function addCookie(e, t) {
            if (!window.localStorage) {
                this.create();
                var o = this.cookieList();
                o[e] = t;
                var n,
                    i = [];
                for (n in o) {
                    i.push(n + "=" + o[n]);
                }
                this._addCookie(i.join(";"));
            }
        },
        _setCookie: function _setCookie() {
            this.cookieList(), c("__TD_LOCAL", "", { expires: 1095, path: "/", domain: location.hostname });
        },
        _addCookie: function _addCookie(e) {
            c("__TD_LOCAL", e, { expires: 1095, path: "/", domain: location.hostname });
        },
        _getCookie: function _getCookie(e) {
            var t = this.cookieList();
            if (t && t[e]) return t[e];
        },
        delCookie: function delCookie() {},
        cookieList: function cookieList() {
            var e = c("__TD_LOCAL");
            return this.format(e);
        },
        addLocalStorage: function addLocalStorage(e, t) {
            window.localStorage &&
                ("sessionId" == e && window.sessionStorage ?
                    sessionStorage.setItem("__TD_" + e, t) :
                    (localStorage["__TD_" + e] = t));
        },
        delLocalStorage: function delLocalStorage(e) {
            window.localStorage && localStorage.removeItem("__TD_" + e);
        },
        getLocalStorage: function getLocalStorage(e) {
            if (window.localStorage)
                return "sessionId" == e && window.sessionStorage ?
                    sessionStorage.getItem("__TD_" + e) :
                    localStorage["__TD_" + e];
        },
        format: function format(e) {
            var t = {};
            if (!e) return t;
            for (var o = e.split(";"), n = o.length, i = 0; i < n; i++) {
                var a = o[i].split("=");
                2 == a.length && (t[a[0]] = a[1]);
            }
            return t;
        }
    }),
    (s.sessionStorage = {
        add: function add(e, t) {
            window.sessionStorage && sessionStorage.setItem("__TD_" + e, t);
        },
        get: function get(e) {
            return sessionStorage.getItem("__TD_" + e);
        },
        remove: function remove(e) {
            sessionStorage.removeItem("__TD_" + e);
        }
    });
    var l,
        h,
        u,
        p,
        f,
        m = !0,
        g = !1;

    function w() {
        (this.url = o), (this.opts = {}), (this.requestArray = new Array());
    }
    (w.prototype = {
        getAjax: function getAjax(e, t, o, n, a) {
            (function(r) {
                var s, d;
                0 < navigator.userAgent.indexOf("MSIE 9.0") ?
                    "MSIE6.0" == (s = navigator.appVersion.split(";")[1].replace(/[ ]/g, "")) || "MSIE7.0" == s ?
                    alert("no support IE6,IE7") :
                    window.XDomainRequest &&
                    ((d = new XDomainRequest()) ?
                        (r.error &&
                            "function" == typeof r.error &&
                            (d.onerror = function() {
                                r.error();
                            }),
                            r.timeout &&
                            "function" == typeof r.timeout &&
                            (d.ontimeout = function() {
                                r.timeout();
                            }),
                            r.success &&
                            "function" == typeof r.success &&
                            (d.onload = function() {
                                r.dataType ?
                                    "json" == r.dataType.toLowerCase() &&
                                    r.success(JSON.parse(d.responseText)) :
                                    r.success(d.responseText);
                            }),
                            d.open(r.type, r.url),
                            d.send(r.param)) :
                        alert("Failed to create XDomainRequest")) :
                    m ?
                    (v.add("td-unique", "true"),
                        (m = !1),
                        (l = i.ajax({
                            type: e,
                            url: t,
                            data: JSON.stringify(o),
                            dataType: "text",
                            success: n,
                            error: a,
                            complete: function complete() {
                                (m = !(l = void 0)), g && (S.getAjax(), (g = !1)), v.delLocalStorage("td-unique");
                            }
                        }))) :
                    (g = !0);
            })({ url: this.url, type: "POST", param: JSON.stringify(o), success: n });
        },
        set: function set(e, t, o) {
            (this.opts = e), this.send(t, o);
        },
        send: function send(e, t) {
            this.getAjax("post", this.url, this.opts, e, t);
        }
    }),
    ((h = window).TDBASE = h.TDBASE || {}),
    (TDBASE.cacheName = "cacheList"),
    (TDBASE.unique = function(e) {
        e.sort();
        for (var t = [e[0]], o = 1; o < e.length; o++) {
            e[o] !== t[t.length - 1] && t.push(e[o]);
        }
        return t;
    }),
    (TDBASE.getArgs = function() {
        for (var e = new Object(), t = h.location.search.substring(1).split("&"), o = 0; o < t.length; o++) {
            var n,
                i = t[o].indexOf("="); -
            1 != i &&
                ((n = t[o].substring(0, i)), (i = t[o].substring(i + 1)), (i = decodeURIComponent(i)), (e[n] = i));
        }
        return e;
    }),
    (TDBASE.getCommon = function(e) {
        var t = v.get("appkey") ? v.get("appkey") : a.appkey;
        return (
            (e = {
                deviceId: a.deviceId,
                appkey: t,
                appProfile: a.appProfile,
                deviceProfile: a.deviceProfile,
                msgs: e.msg
            }),
            a.appContext && (e.appContext = a.appContext),
            e
        );
    }),
    (TDBASE.getCommonMsg = function(e, t, o, n, i, a) {
        return {
            type: 2,
            data: { id: e, start: t, status: o, duration: n || 0, pages: a ? [a] : [], events: i || [] }
        };
    }),
    (TDBASE.addSessionStart = function(e, t) {
        v.add("lastSession", JSON.stringify({ id: r.data.id, start: r.data.start })),
            (o = (o = v.get("td-hold-event")) && JSON.parse(o));
        var o = TDBASE.getCommonMsg(r.data.id, r.data.start, t, e, o);
        TDBASE.addMsg(o), v.delLocalStorage("td-hold-event");
    }),
    (TDBASE.equal = function(e, t) {
        if ((void 0 === e ? "undefined" : n(e)) != (void 0 === t ? "undefined" : n(t))) return !1;
        if (n(e.length) != n(t.length)) return !1;
        var o = !0,
            i = [],
            a = [];
        for (r in e) {
            "count" === r || "start" === r || i.push(r);
        }
        for (r in t) {
            "count" === r || "start" === r || a.push(r);
        }
        if (i.length != a.length) return !1;
        for (var r = 0, s = a.length; r < s; r++) {
            i.push(a[r]);
        }
        var d = TDBASE.unique(i);
        for (r = 0, s = d.length; r < s; r++) {
            if (!(d[r] in e && d[r] in t)) return !1;
            if ("object" == n(e[d[r]]) && "object" == n(t[d[r]])) o = TDBASE.equal(e[d[r]], t[d[r]]);
            else if (e[d[r]] !== t[d[r]]) return !1;
        }
        return o;
    }),
    (TDBASE.addGenre = function(e, t, o) {
        if (v.get("sessionMsg")) {
            o && o(e);
            var n = (o = JSON.parse(v.get("sessionMsg"))).msg[o.msg.length - 1].data[t];
            if ("events" !== t) n.push(e), v.add("sessionMsg", JSON.stringify(o));
            else {
                if (0 != n.length) {
                    for (var i = !1, a = 0; a < n.length; a++) {
                        if (TDBASE.equal(n[a], e)) {
                            (i = !0), (n[a].count += 1), (n[a].start = e.start);
                            break;
                        }
                    }
                    i || n.push(e);
                } else n.push(e);
                v.add("sessionMsg", JSON.stringify(o));
            }
        }
    }),
    (TDBASE.lealSet = function(e) {
        v.add("leavetime", e), v.add("leaveSession", parseInt((e - b.get("SessionStart")) / 1e3));
    }),
    (TDBASE.addMsg = function(e) {
        var t;
        v.get("sessionMsg") ?
            ((t = JSON.parse(v.get("sessionMsg"))).msg.push(e), v.add("sessionMsg", JSON.stringify(t))) :
            v.add("sessionMsg", JSON.stringify({ msg: [e] }));
    }),
    (u = {
        currentPage: null,
        pageStartTime: 0,
        ref: "",
        logoutCalled: !1,
        init: function init() {
            setTimeout(function() {
                    u.pageLogout();
                }, 5e3),
                (window.TDAPP = window.TDAPP || {}),
                (window.TDAPP.onPage = u.onPage),
                s.autoTrack && ((u.currentPage = window.location.href), (u.ref = document.referrer));
        },
        onPage: function onPage(e) {
            var t = new Date().getTime();
            u.pageLogout("force"),
                u.pageEnter(e, u.currentPage, t),
                (u.ref = u.currentPage),
                (u.currentPage = e),
                (u.pageStartTime = t),
                S.getAjax();
        },
        pageEnter: function pageEnter(e, t, o) {
            (t = { name: e, start: o, duration: 0, refer: t || document.referrer }), TDBASE.addGenre(t, "pages");
        },
        pageLogout: function pageLogout(e) {
            if ("force" !== e) {
                if (u.logoutCalled) return;
                u.logoutCalled = !0;
            }
            var t = null,
                o = 0,
                n = null;
            if (s.autoTrack)
                (t = u.currentPage || window.location.href),
                (o = u.pageStartTime || d),
                (n = u.ref || document.referrer);
            else {
                if (!u.currentPage) return;
                (t = u.currentPage), (o = u.pageStartTime), (n = u.ref || document.referrer);
            }
            (e = new Date().getTime()),
            TDBASE.lealSet(e),
                TDBASE.addGenre({ name: t, start: o, duration: 6, refer: n }, "pages");
        }
    }).init(),
        (p = {
            init: function init() {
                try {
                    var e = s.localStorage.get("profile");
                    e &&
                        ((e = JSON.parse(e)),
                            (e = p._transform(e)),
                            (a.appContext = a.appContext || {}),
                            (a.appContext.account = e));
                } catch (e) {
                    console.error(e);
                }
            },
            _transform: function _transform(e) {
                return (
                    ((e = JSON.parse(JSON.stringify(e))).accountId = e.profileId),
                    (e.type = e.profileType),
                    delete e.profileType,
                    delete e.profileId,
                    e
                );
            },
            _transformInverse: function _transformInverse(e) {
                return (
                    ((e = JSON.parse(JSON.stringify(e))).profileId = e.accountId),
                    (e.profileType = e.type),
                    delete e.type,
                    delete e.accountId,
                    e
                );
            },
            login: function login(e) {
                p._event(e, "login");
            },
            register: function register(e) {
                p._event(e, "register");
            },
            updateProfile: function updateProfile(e) {
                p._event(e, "update");
            },
            _chekProfile: function _chekProfile() {
                return "object" === n(a.appContext) && "object" === n(a.appContext.account) ?
                    a.appContext.account :
                    null;
            },
            _event: function _event(e, t) {
                if (!e || "object" !== (void 0 === e ? "undefined" : n(e))) return console.log("profile淇℃伅蹇呭～!");
                if ("update" !== t && !e.profileId && !/0{1}/.test(e.profileId))
                    return console.log("profileId 淇℃伅涓哄繀濉�!");
                if ("update" !== t && "number" != typeof e.profileType) return console.log("profileType 涓哄繀濉�!");
                var o,
                    i = p._getProfile(e, t),
                    r = {
                        profileId: "_setId",
                        profileType: "_setProfileType",
                        name: "_setName",
                        gender: "_setGender",
                        age: "_setAge"
                    },
                    d = new RegExp("^property[1-9]$");
                for (o in e) {
                    var c,
                        l = e[o],
                        h = r[o];
                    if (!h || ("update" === t && "profileId" === o)) {
                        if ((d.test(o) || "property10" === o) && (c = p._setProperty(i, o, l)))
                            return void console.log(c);
                    } else if ((c = p[h](i, l))) return void console.log(c);
                }
                (a.appContext = a.appContext || {}), (a.appContext.account = i);
                var u = p._transformInverse(i);
                s.localStorage.add("profile", JSON.stringify(u)),
                    (i = p._transform(i)),
                    (u = p._transform(e)),
                    y.setProfile(u, t);
            },
            _getProfile: function _getProfile(e, t) {
                var o = {};
                return (
                    a.appContext && a.appContext.account && (o = JSON.parse(JSON.stringify(a.appContext.account))),
                    "update" == t || e.profileId === o.accountId ? o : {}
                );
            },
            _setId: function _setId(e, t) {
                if (!t && !/0{1}/.test(t)) return "profileId涓哄繀濉瓧娈碉紒";
                e.accountId = t;
            },
            _setProfileType: function _setProfileType(e, t) {
                if ("number" != typeof t || t != t || t < -1 || (6 < t && t < 11) || 20 < t)
                    return "璇蜂笂浼犳纭殑profileType";
                e.type = t;
            },
            _setName: function _setName(e, t) {
                if ("string" != typeof t) return "profile name 绫诲瀷閿欒";
                e.name = t;
            },
            _setAge: function _setAge(e, t) {
                if ("number" != typeof t || t != t) return "profile age 绫诲瀷閿欒";
                e.age = t;
            },
            _setGender: function _setGender(e, t) {
                if (0 !== t && (1 !== t) & (2 !== t)) return "profile gender 绫诲瀷閿欒";
                e.gender = t;
            },
            _setProperty: function _setProperty(e, t, o) {
                if (("number" == typeof o && o != o) || ("string" != typeof o && "number" != typeof o))
                    return "profile property 绫诲瀷閿欒";
                e[t] = o;
            }
        }),
        (window.TDAPP = window.TDAPP || {}),
        (window.TDAPP.login = p.login),
        (window.TDAPP.register = p.register),
        (window.TDAPP.updateProfile = p.updateProfile),
        (window.TDAPP.ProfileType = {
            0: "ANONYMOUS",
            1: "REGISTERED",
            2: "SINA_WEIBO",
            3: "QQ",
            4: "QQ_WEIBO",
            5: "ND91",
            6: "WEIXIN",
            11: "TYPE1",
            12: "TYPE2",
            13: "TYPE3",
            14: "TYPE4",
            15: "TYPE5",
            16: "TYPE6",
            17: "TYPE7",
            18: "TYPE8",
            19: "TYPE9",
            20: "TYPE10"
        }),
        p.init(),
        (f = {
            isObject: function isObject(e) {
                return e && "object" === (void 0 === e ? "undefined" : n(e));
            },
            isStrNotEmpty: function isStrNotEmpty(e) {
                return e || /0{1}/.test(e);
            },
            isNumber: function isNumber(e) {
                return "number" == typeof e && e == e;
            },
            isCurrencyTypeAvailabal: function isCurrencyTypeAvailabal(e) {
                return e && "string" == typeof e && 3 === e.length;
            },
            _checkParam: function _checkParam(e) {
                return f.isObject(e) ?
                    f.isStrNotEmpty(e.orderId) ?
                    f.isNumber(e.amount) ?
                    !!f.isCurrencyTypeAvailabal(e.currencyType) ||
                    (console.warn("璇疯緭鍏ユ纭殑currencyType!"), !1) :
                    (console.warn("璇疯緭鍏ユ纭殑amount!"), !1) :
                    (console.warn("璇疯緭鍏ユ纭殑orderId!"), !1) :
                    (console.warn("璇疯緭鍏ユ纭殑鍙傛暟!"), !1);
            },
            onPlaceOrder: function onPlaceOrder(e) {
                f._checkParam(e) &&
                    ((e = { count: 1, start: new Date().getTime(), domain: "iap", id: "placeOrder", params: e }),
                        y._saveAndFetch(e));
            },
            onOrderPaySucc: function onOrderPaySucc(e) {
                f._checkParam(e) &&
                    ((e = JSON.parse(JSON.stringify(e))).paymentType &&
                        f.isStrNotEmpty(e.paymentType) &&
                        (e.payType = e.paymentType),
                        delete e.paymentType,
                        (e = { count: 1, start: new Date().getTime(), domain: "iap", id: "pay", params: e }),
                        y._saveAndFetch(e));
            },
            onCancelOrder: function onCancelOrder(e) {
                f._checkParam(e) &&
                    ((e = { count: 1, start: new Date().getTime(), domain: "iap", id: "cancelOrder", params: e }),
                        y._saveAndFetch(e));
            }
        }),
        (window.TDAPP = window.TDAPP || {}),
        (window.TDAPP.onPlaceOrder = f.onPlaceOrder),
        (window.TDAPP.onOrderPaySucc = f.onOrderPaySucc),
        (window.TDAPP.onCancelOrder = f.onCancelOrder);
    var v = s.localStorage,
        b = s.sessionStorage,
        S = {
            timedif: void 0,
            state: 1,
            deviceId: 0,
            sessionId: 0,
            local: [],
            sendInit: 0,
            set: function set() {
                try {
                    this.setDeviceId(),
                        this.setSession(),
                        this.setSessionTime(),
                        this.setInitTime(),
                        this.setPartner(),
                        this.setResolution(),
                        this.addlastSession(),
                        this.setPageEnter(),
                        this.getAjax(1);
                } catch (e) {
                    console.log(e);
                }
            },
            setDeviceId: function setDeviceId() {
                if (cc.sys.localStorage.getItem("_TD_deviceId"))
                    this.deviceId = cc.sys.localStorage.getItem("_TD_deviceId");
                else {
                    this.sendInit = 1;
                    for (
                        var e = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""), t = [], o = e.length, n = 0; n < 16; n++
                    ) {
                        t[n] = e[0 | (Math.random() * o)];
                    }
                    (this.deviceId = t.join("")), cc.sys.localStorage.setItem("_TD_deviceId", this.deviceId);
                }
                a.deviceId = this.deviceId;
            },
            setSession: function setSession() {
                var e, t;
                if (
                    (b.get("sessionId") && v.get("appkey") == a.appkey ?
                        (t = b.get("sessionId")) :
                        ((e = new Date().getTime()),
                            (t = -1 < this.deviceId.indexOf("-") ? this.deviceId.split("-")[0] + e : this.deviceId + e),
                            (this.sendInit = 0 == this.sendInit ? 2 : this.sendInit),
                            b.add("sessionId", t)),
                        0 < 32 - t.length)
                )
                    for (var o = 0, n = 32 - t.length; o < n; o++) {
                        t += "0";
                    }
                32 - t.length < 0 && (t = t.substring(0, 32)), (r.data.id = this.sessionId = t);
            },
            setSessionTime: function setSessionTime() {
                var e = new Date().getTime();
                b.get("SessionStart") && v.get("appkey") == a.appkey ?
                    (e = b.get("SessionStart")) :
                    b.add("SessionStart", e),
                    (r.data.start = parseInt(e));
            },
            setInitTime: function setInitTime() {
                v.get("initTime") ?
                    (a.appProfile.initTime = parseInt(v.get("initTime"))) :
                    ((a.appProfile.initTime = d), v.add("initTime", d));
            },
            setPartner: function setPartner() {
                var t = b.get("td_channel"),
                    o = e;
                t ? (a.appProfile.partner = t) : null != o && (b.add("td_channel", o), (a.appProfile.partner = o));
            },
            setResolution: function setResolution() {
                var e = [window.screen.width, window.screen.height];
                window.devicePixelRatio && e.push(window.devicePixelRatio), (a.deviceProfile.pixel = e.join("*"));
            },
            addlastSession: function addlastSession() {
                var e = v.get("lastSession");
                void 0 === e && (v.delLocalStorage("sessionMsg"), v.delLocalStorage("lastSession")),
                    e ?
                    (e = JSON.parse(e)).id != r.data.id &&
                    ((e = TDBASE.getCommonMsg(e.id, e.start, 3, parseInt(v.get("leaveSession")))),
                        TDBASE.addMsg(e),
                        (this.timedif = parseInt((r.data.start - v.get("leavetime")) / 1e3)),
                        (v.get("appkey") && v.get("appkey") != a.appkey) ||
                        (TDBASE.addSessionStart(this.timedif, 1), this.addAppInitEvent())) :
                    (TDBASE.addSessionStart(0, 1), this.addAppInitEvent());
            },
            setPageEnter: function setPageEnter() {
                var e;
                s.autoTrack &&
                    ((e = {
                            name: "http://localhost:1111/",
                            start: new Date().getTime(),
                            duration: 6,
                            refer: "http://localhost:1111/"
                        }),
                        TDBASE.addGenre(e, "pages"));
            },
            addAppInitEvent: function addAppInitEvent() {
                var e;
                0 != this.sendInit &&
                    ((e = { id: "init", domain: "app", start: d || new Date().getTime(), count: 1, params: { first: !0 } }),
                        2 == this.sendInit && (e.params.first = !1),
                        TDBASE.addGenre(e, "events"));
            },
            getAjax: function getAjax() {
                var e = this,
                    t = new w();
                localStorage.__TD_sessionMsg || TDBASE.addSessionStart(0, 2);
                var o,
                    n = JSON.parse(v.get("sessionMsg")),
                    i = TDBASE.getCommon(n),
                    r = localStorage["__TD_td-init-event"];
                !r ||
                    ((o = i.msgs[i.msgs.length - 1]) &&
                        ((n = o.data.events), (o.data.events = n.concat(JSON.parse(r))))),
                    v.delLocalStorage("td-init-event");
                for (var s = [], c = 0; c < i.msgs.length; c++) {
                    var l = i.msgs[c];
                    (2 !== l.data.status ||
                        (l.data.pages && 0 !== l.data.pages.length) ||
                        (l.data.events && 0 !== l.data.events.length)) &&
                    s.push(l);
                }
                0 !== s.length &&
                    ((i.msgs = s),
                        v.get("appkey") && v.get("appkey") != a.appkey ?
                        t.set(
                            i,
                            function() {
                                v.delLocalStorage("sessionMsg"),
                                    (a.appProfile.initTime = d),
                                    v.add("initTime", d),
                                    TDBASE.addSessionStart(0, 1),
                                    e.addAppInitEvent(),
                                    e.getAjax();
                            },
                            function(e) {
                                console.log(e);
                            }
                        ) :
                        t.set(
                            i,
                            function() {
                                v.delLocalStorage("sessionMsg"), TDBASE.addSessionStart(0, 2);
                            },
                            function(e) {
                                console.log(e);
                            }
                        ),
                        v.add("appkey", a.appkey));
            }
        };
    S.set();
    var y = {
        set: function set(e, t, o, i) {
            var a;
            if (e || /0{1}/.test(e)) {
                if (0 < arguments.length)
                    try {
                        var r = { count: 1, start: new Date().getTime() };
                        if (
                            (null != e && (r.id = "string" != typeof e ? JSON.stringify(e) : e),
                                (r.label = null != t ? ("string" != typeof t ? JSON.stringify(t) : t) : ""),
                                null != o &&
                                ("object" != (void 0 === (a = o) ? "undefined" : n(a)) ||
                                    "[object object]" != Object.prototype.toString.call(a).toLowerCase() ||
                                    a.length ||
                                    (r.params = o)),
                                i && "smart" === i)
                        )
                            r.type = "smart";
                        else if (void 0 !== i) {
                            if ("number" != typeof i || isNaN(i)) return void console.error("value鍙兘涓簄umber");
                            r.value = i;
                        }
                        y._saveAndFetch(r);
                    } catch (e) {}
            } else console.warn("event  Id涓哄繀濉瓧娈碉紒");
        },
        setProfile: function setProfile(e, t) {
            (e = { count: 1, start: new Date().getTime(), domain: "account", id: t, params: e }), y._saveAndFetch(e);
        },
        _saveAndFetch: function _saveAndFetch(e) {
            l
                ?
                TDBASE.addGenre(e, "events", function(e) {
                    var t = v.get("td-hold-event"),
                        o = [];
                    if ((o.push(e), t)) {
                        t = JSON.parse(t);
                        for (var n = 0; n < t.length; n++) {
                            if (TDBASE.equal(t[n], e)) {
                                (t[n].count += 1), (t[n].start = e.start);
                                break;
                            }
                        }
                        v.add("td-hold-event", JSON.stringify(t));
                    } else v.add("td-hold-event", JSON.stringify(o));
                }) :
                (TDBASE.addGenre(e, "events"),
                    setTimeout(function() {
                        S.getAjax();
                    }, 500));
        },
        unload: function unload() {
            try {
                S.getAjax();
            } catch (e) {}
        }
    };
    (window.TDAPP = window.TDAPP || {}), (window.TDAPP.onEvent = y.set);
};
// setTimeout(function () {
//     o();
// }, 4e3);